package com.mhkj.base.templete.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.mhkj.base.templete.entity.PlanTempleteData;
import com.mhkj.base.templete.service.PlanTempleteDataService;
import com.mics.core.common.componet.JsonHandler;
import com.mics.core.common.componet.Pagination;
import com.mics.core.common.componet.ResponseMessage;
import com.mics.core.system.base.controller.BaseController;
import com.mics.core.system.organizational.bean.Company;
import com.mics.core.system.organizational.bean.Office;
import com.mics.core.system.organizational.bean.Post;
import com.mics.core.system.organizational.service.OrgService;

/**
 * 模板数据
 * @author mics
 * @date 2018年7月20日
 * @version 1.0
 */
@RestController
@RequestMapping("/planTempData")
public class PlanTempDataController extends BaseController<PlanTempleteData>{
	@Resource
	private PlanTempleteDataService planTempleteDataService;
	@Resource
	private JsonHandler jsonHandler;
	@Resource
	private OrgService orgService;
	
	@Resource
	public void setPlanTempleteDataService(PlanTempleteDataService planTempleteDataService) {
		super.setBaseService(planTempleteDataService);
	}
	
	@RequestMapping("/listByPage")
	@ResponseBody
	public void listByPage(HttpServletResponse response,PlanTempleteData planTempleteData,int pageIndex,int pageSize){
		Pagination<PlanTempleteData> planTempletePagination = planTempleteDataService.listByPage(planTempleteData, pageIndex,  pageSize);
		List<PlanTempleteData> planTempleteDatas = planTempletePagination.getData();
		if(planTempleteDatas!=null && planTempleteDatas.size() > 0){
			for(PlanTempleteData planData:planTempleteDatas){
				String companyId = planData.getCompanyId();
				Company company = orgService.getCompanyById(companyId);
				planData.setCompanyName(company.getCompanyname());
				String officeId = planData.getOfficeId();
				Office office = orgService.officeInfo(officeId);
				planData.setOfficeName(office.getName());
				String postId = planData.getPostId();
				Post post = orgService.getRoleInfo(postId);
				planData.setPostName(post.getName());
			}
		}
		jsonHandler.sendJsonString(response, true,"获取数据成功！", planTempletePagination, 
				new String[]{"NO","businessType.typeName","nodeName","nodeProperty.value","completeStandard","deadline","deadlineDesc","companyName","officeName","postName","supervise","remark"},
				"NO","busiMode","nodeName","nodeProperty","completeStandard","deadline","deadlineDesc","companyName","officeName","postName","supervise","remark");
	}

	@Override
	@RequestMapping("/save")
	public ResponseMessage save(PlanTempleteData t) {
		return super.save(t);
	}

	@Override
	@RequestMapping("/edit")
	public ResponseMessage edit(PlanTempleteData t) {
		return super.edit(t);
	}

	@Override
	@RequestMapping("/del")
	public ResponseMessage del(PlanTempleteData t) {
		return super.del(t);
	}

	@Override
	@RequestMapping("/info")
	public PlanTempleteData info(long id) {
		return super.info(id);
	}
	
	
}
